package com.netintech.project.monitor.controller;

import java.util.List;

import com.netintech.project.monitor.domain.dto.SysLoginInfoDto;
import com.netintech.project.monitor.service.SysLoginInfoService;
import com.netintech.project.system.domain.dto.CommonsDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.netintech.common.utils.poi.ExcelUtil;
import com.netintech.core.aspectj.lang.annotation.Log;
import com.netintech.core.aspectj.lang.enums.BusinessType;
import com.netintech.core.web.controller.BaseController;
import com.netintech.core.web.domain.RequestResult;
import com.netintech.core.web.page.TableDataInfo;
import com.netintech.project.monitor.domain.SysLogininfor;

/**
 * 系统访问记录
 *
 * @author admin
 */
@RestController
@RequestMapping("monitor/loginInfo")
public class SysLoginInfoController extends BaseController {
    @Autowired
    private SysLoginInfoService logininforService;

    @RequestMapping("index")
    public RequestResult list(@RequestBody SysLoginInfoDto sysLoginInfoDto) {
        return RequestResult.success(logininforService.queryLoginInfoPage(sysLoginInfoDto));
    }

    @RequestMapping("export")
    @Log(title = "登陆日志", businessType = BusinessType.EXPORT)
    public RequestResult export(@RequestBody SysLogininfor logininfor) {
        List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
        ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);
        return util.exportExcel(list, "登陆日志");
    }

    @RequestMapping("deleteBatch")
    @Log(title = "登陆日志", businessType = BusinessType.DELETE)
    public RequestResult remove(@RequestBody CommonsDto commonsDto) {
        Long[] ids = commonsDto.getIds();
        if (ids == null || ids.length == 0) {
            return RequestResult.error("ids为空");
        }
        return returnResult(logininforService.deleteLogininforByIds(ids));
    }

    @Log(title = "登陆日志", businessType = BusinessType.CLEAN)
    @RequestMapping("clean")
    public RequestResult clean() {
        logininforService.cleanLogininfor();
        return RequestResult.success();
    }
}
